#include "Key.h"
#include "multi_button.h"
#include "main.h"

struct Button Button0 = {0};

void Key_InitConfig(void)
{
	FL_GPIO_InitTypeDef GPIO_InitStruct = {0};
	GPIO_InitStruct.pin = FL_GPIO_PIN_12;
	GPIO_InitStruct.mode = FL_GPIO_MODE_INPUT;
	GPIO_InitStruct.pull = FL_DISABLE;
	FL_GPIO_Init(GPIOB, &GPIO_InitStruct);
    button_init(&Button0, Key_ReadPinLevel, 0, 0);
	button_attach(&Button0, PRESS_DOWN, Button0_PRESS_DOWN_Handler);
	button_attach(&Button0, PRESS_UP, Button0_PRESS_UP_Handler);
	button_attach(&Button0, PRESS_REPEAT, Button0_PRESS_PRESS_REPEAT_Handler);
	button_attach(&Button0, LONG_PRESS_START, Button0_LONG_PRESS_START_Handler);
	button_attach(&Button0, SINGLE_CLICK, Button0_SINGLE_CLICK_Handler);
	button_attach(&Button0, DOUBLE_CLICK, Button0_DOUBLE_CLICK_Handler);
    button_start(&Button0);
}

uint8_t Key_ReadPinLevel(uint8_t buttonx)
{
	uint8_t buttonxlevel = 0;
	switch(buttonx)
	{
		case BUTTON0:
			buttonxlevel = FL_GPIO_GetInputPin(GPIOB, FL_GPIO_PIN_12);
			break;
		default:
			buttonxlevel = 0;
			break;
	}
	return buttonxlevel;
}

void Button0_PRESS_DOWN_Handler(void * button0)
{
  	DEBUG_Printf(0, "Button0_PRESS_DOWN.");  
}

void Button0_PRESS_UP_Handler(void * button0)
{
  	DEBUG_Printf(0, "Button0_PRESS_UP.");  
}

void Button0_PRESS_PRESS_REPEAT_Handler(void * button0)
{
	DEBUG_Printf(0, "Button0_PRESS_REPEAT.");	
}

void Button0_LONG_PRESS_START_Handler(void * button0)
{
   	DEBUG_Printf(0, "Button0_LONG_PRESS_START."); 
}

void Button0_SINGLE_CLICK_Handler(void * button0)
{
  	DEBUG_Printf(0, "Button0_SINGLE_CLICK.");  
}

void Button0_DOUBLE_CLICK_Handler(void * button0)
{
  	DEBUG_Printf(0, "Button0_DOUBLE_CLICK.");  
}
